package com.ymatou.iapi.dglogin.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dglogin.parameter.BuyerSendVerifyCodeBean;
import com.ymatou.iapi.dglogin.service.BuyerSendVerifyCodeCall;
import com.ymatou.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.ValidationCode;
import com.ymttest.database.sqlwapper.YmtValidationCodeWapperV2;
import com.ymttest.utils.TestDataManager;
/**
*发送买家手机验证码
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_BuyerSendVerifyCode{
	private static BuyerSendVerifyCodeBean buyersendverifycodeBean;
	private static BuyerSendVerifyCodeCall buyersendverifycodeCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("发送买家手机验证码");
	}

	@Before
	public void caseUp() {
		buyersendverifycodeBean=new BuyerSendVerifyCodeBean();
		buyersendverifycodeCall=new BuyerSendVerifyCodeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(buyersendverifycodeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BuyerSendVerifyCode_001() {
		Logger.start(true,"发送买家手机验证码成功");
		try {
			buyersendverifycodeBean.setMobile(TestDataManager.getPhoneNum());
			buyersendverifycodeCall.setData(buyersendverifycodeBean);
			buyersendverifycodeCall.callService();			
			Logger.verifyEquals("true", buyersendverifycodeCall.getString("success"), "验证success");
			ValidationCode vc = new YmtValidationCodeWapperV2().getValidateData(buyersendverifycodeBean.getMobile());
			Logger.verifyNotNull( vc, "验证有数据");
			Logger.debug(com.ymt.core.tool.FormatUtil.beanToGSONString(vc));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_BuyerSendVerifyCode_002() {
		Logger.start(true,"不输入mobile失败");
		try {
			buyersendverifycodeCall.setData(buyersendverifycodeBean);
			buyersendverifycodeCall.callService();			
			Logger.verifyEquals("false", buyersendverifycodeCall.getString("success"), "验证success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BuyerSendVerifyCode_003() {
		Logger.start(true,"发送买家手机验证码,增加区号");
		try {
			//国内不加区号? 国外区号发送失败 ?
			String AreaCode="86";
			buyersendverifycodeBean.setMobileAreaCode(AreaCode);
			buyersendverifycodeBean.setMobile(TestDataManager.getPhoneNum());
			buyersendverifycodeCall.setData(buyersendverifycodeBean);
			buyersendverifycodeCall.callService();			
			Logger.verifyEquals("true", buyersendverifycodeCall.getString("success"), "验证success");
			ValidationCode vc = new YmtValidationCodeWapperV2().getValidateData(buyersendverifycodeBean.getMobile());
			Logger.verifyNotNull( vc, "验证有数据");
			Logger.debug(com.ymt.core.tool.FormatUtil.beanToGSONString(vc));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BuyerSendVerifyCode_004() {
		Logger.start(true,"发送买家手机验证码成功-带shopid");
		try {
			buyersendverifycodeBean.setMobile(TestDataManager.getPhoneNum());
			buyersendverifycodeBean.setShopId(1);
			buyersendverifycodeCall.setData(buyersendverifycodeBean);
			buyersendverifycodeCall.callService();			
			Logger.verifyEquals("true", buyersendverifycodeCall.getString("success"), "验证success");
			ValidationCode vc = new YmtValidationCodeWapperV2().getValidateData(buyersendverifycodeBean.getMobile());
			Logger.verifyNotNull( vc, "验证有数据");
			Logger.debug(com.ymt.core.tool.FormatUtil.beanToGSONString(vc));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}